/*
 * @Author: Lin Hongwei
 * @Date: 2022-10-17 09:58:58
 * @LastEditTime: 2022-11-05 14:01:37
 * @LastEditors: Lin Hongwei
 * @email: 1365755396@qq.com
 * @CSDN: https://blog.csdn.net/weixin_45429409
 * @Description: 服务全局配置文件
 */
const koa = require('koa');
const router = require('./router');
const KoaBody = require('koa-body');
const ResponseMiddleware = require('./middleware/response.middleware');
const RequestMiddleware = require('./middleware/request.middleware');
const AuthMiddleware = require('./middleware/auth.middleware');
const KoaStatic = require('koa-static');
const path = require('path');

const app = new koa();


app.use(KoaBody({
  multipart: true,//开启表单格式
}))
app.use(KoaStatic(path.join(__dirname,'./view')))
app.use(RequestMiddleware);//请求处理中间件
app.use(ResponseMiddleware());//实现统一响应中间件
app.use(AuthMiddleware([
  '/login',
  '/register',
  '/view'
]))


app.use(router.routes()).use(router.allowedMethods());


module.exports = app